home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C26 / Batchmail.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  2.0 KB  |  64 lines

  1. //: C26:Batchmail.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // Sends mail to a list using Unix fastmail
  7. #include "../require.h"
  8. #include <iostream>
  9. #include <fstream>
  10. #include <string>
  11. #include <strstream>
  12. #include <cstdlib> // system() function
  13. using namespace std;
  14.  
  15. string subject("New Intensive Workshops");
  16. string from("Bruce@EckelObjects.com");
  17. string replyto("Bruce@EckelObjects.com");
  18. ofstream logfile("BatchMail.log");
  19.  
  20. int main(int argc, char* argv[]) {
  21.   requireArgs(argc, 2,
  22.     "Usage: Batchmail namelist mailfile");
  23.   ifstream names(argv[1]);
  24.   assure(names, argv[1]);
  25.   string name;
  26.   while(getline(names, name)) {
  27.     ofstream msg("m.txt");
  28.     assure(msg, "m.txt");
  29.     msg << "To be removed from this list, "
  30.       "DO NOT REPLY TO THIS MESSAGE. Instead, \n"
  31.       "click on the following URL, or visit it "
  32.       "using your Web browser. This \n"
  33.       "way, the proper email address will be "
  34.       "removed. Here's the URL:\n"
  35.       << "http://www.mindview.net/cgi-bin/"
  36.       "mlm.exe?subject-field=workshop-email-list"
  37.       "&command-field=remove&email-address="
  38.       << name << "&submit=submit\n\n"
  39.       "------------------------------------\n\n";
  40.     ifstream text(argv[2]);
  41.     assure(text, argv[1]);
  42.     msg << text.rdbuf() << endl;
  43.     msg.close();
  44.     string command("fastmail -F " + from + 
  45.       " -r " + replyto + " -s \"" + subject + 
  46.       "\" m.txt " + name);
  47.     system(command.c_str());
  48.     logfile << command << endl;
  49.     static int mailcounter = 0;
  50.     const int bsz = 25; 
  51.     char buf[bsz];
  52.     // Convert mailcounter to a char string:
  53.     ostrstream mcounter(buf, bsz);
  54.     mcounter << mailcounter++ << ends;
  55.     if((++mailcounter % 500) == 0) {
  56.       string command2("fastmail -F " + from + 
  57.         " -r " + replyto + " -s \"Sent " +
  58.         string(buf) + 
  59.         " messages \" m.txt eckel@aol.com");
  60.       system(command2.c_str());
  61.     }
  62.   }
  63. } ///:~
  64.